import GPUImage
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var renderView: RenderView!
    @IBOutlet weak var imageView: UIImageView!

    var picture: PictureInput!
    var filter: ImageGrayscaleTransparency!

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        // Filtering image for display
//        picture = PictureInput(image: UIImage(named: "005")!.withRenderingMode(.alwaysOriginal))
//        filter = ImageGrayscaleTransparency(startValue: 0.6, endValue: 0.9)
//        picture --> filter --> renderView
//        picture.processImage(synchronously: true)

        let image = UIImage(named: "005")!
        var outputImage: UIImage?
        let picture = PictureInput(image: image)
        let transparency = ImageGrayscaleTransparency()
        let pictureOutput = PictureOutput()
        transparency.addTarget(pictureOutput)
        picture.addTarget(transparency)
        pictureOutput.onlyCaptureNextFrame = true
        pictureOutput.encodedImageAvailableCallback = { data in
            outputImage = .init(data: data)
        }
        picture.processImage(synchronously: true)
        imageView.image = outputImage
    }
}
